﻿@{ 
    CurrentUser user = ViewBag.CurrentUser;
    string action = ViewContext.RouteData.Values["action"].ToString();
    IEnumerable<dynamic> fieldData = Html.GetFieldList((string)ViewBag.Table, action, user, PageAdmin.Common.FromEnum.Member);
    string guid = Html.Guid();
}
<div class="main">
    <script src="~/Incs/UEditor/ueditor.forAdmin.config.js" type="text/javascript"></script>
    <script src="~/Incs/UEditor/ueditor.all.min.js" type="text/javascript"></script>
    <form method="post" class="form  ui-validForm" data-validate-params="beforeSubmit:'BeforeSubmit'">
        <div class="form-group">
            <label class="control-label">用户组：</label>
            <div class="controls">
                <select class="form-control ui-queryString" name="memberGroupId" id="memberGroupId" data-source="@Html.GetCanAdminMemberGroupListJson()" data-custom-params="dataSourceFrom:'attr'"></select>
                <span class="help-block"></span>
            </div>
        </div>

        <div class="form-group">
            <label class="control-label">所属部门：</label>
            <div class="controls">
                <select class="form-control ui-selectBind" name="departmentId" id="departmentId" data-source="@Html.GetDepartmentListJson()" data-custom-params="dataSourceFrom:'attr',isTree:true,onlySelectFinal:true">
                    <option value="0">无</option>
                </select>
                <span class="help-block"></span>
            </div>
        </div>

        <div class="form-group">
            <label class="control-label">用户名</label>
            <div class="controls">
                <input type="text" class="form-control" name="username" id="username" data-validate="dataType:'username',nullMsg:'请填写用户名!',errorMsg:'用户名控制在2-16字符之间，且只能是数字、字母、下划线或中文字符组成!',checkerrorMsg:'用户名已经存在，请重新输入！',checkUrl:'@Url.Action("CheckExists",new {id=Request.QueryString["id"],fieldName = "用户名",area="admin"})'" maxlength="50">
                <span class="help-block"></span>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label">密码</label>
            <div class="controls">
                <input type="password" class="form-control  ui-passwordEye" name="password" id="password" data-validate="dataType:'password',nullMsg:'请填写密码!',errorMsg:'密码长度控制在2到16位字符之间！'" maxlength="16">
                <span class="help-block"></span>
            </div>
        </div>

        <div class="form-group">
            <label class="control-label">邮箱：</label>
            <div class="controls">
                <input type="text" class="form-control" name="email" id="email" data-validate="dataType:'email',ignoreEmpty:true,nullMsg:'请填写邮箱！',errorMsg:'邮箱格式错误！'" maxlength="50">
                <span class="help-block"></span>
            </div>
        </div>
        <div class="form-group">
            <label class="control-label">手机号：</label>
            <div class="controls">
                <input type="text" class="form-control" name="mobile" id="mobile" data-validate="dataType:'mobile',ignoreEmpty:true,nullMsg:'请填写手机号！',errorMsg:'手机号码格式错误！'" maxlength="15">
                <span class="help-block"></span>
            </div>
        </div>
        @{
        string beforeSubmitJs = "";
        var data = new ViewDataDictionary();
        data.Add("from", "member");
        data.Add("guid", guid);
        data.Add("currentUser", ViewBag.CurrentUser);
        data.Add("memberGroupId", ViewBag.MemberGroupId);
        data.Add("i", 0);
        int i = 0;
        if (fieldData != null)
        {
            foreach (var row in fieldData)
            {
                data["i"] = i;
                beforeSubmitJs += row.BeforeSubmitJs;
                Html.RenderPartial("~/Areas/E/Views/CustomForm/FormPartial.cshtml", (object)row, data);
                i++;
            }
        }

        }
        <script type="text/javascript">
                    function BeforeSubmit() {
                        @Html.Raw(beforeSubmitJs)
                        return true;
                    }
        </script>

        <div class="submit-footerbar">
            <label class="control-label"></label>
            <div class="controls">
                <input type="hidden" id="Id" name="Id" value="0" />
                <input type="hidden" id="State" name="State" value="1" />
                <input type="hidden" id="IsAdmin" name="IsAdmin" value="0" />
                <input type="hidden" id="Logins" name="Logins" value="0" />
                <input type="hidden" id="Guid" name="Guid" value="@guid" />
                <button type="button" class="btn btn-sm btn-primary ui-pagePost" data-custom-params="url:'@Url.ActionUrl()',callBack:'PostRefreshBack'">提交</button>
                <button type="button" class="btn btn-sm btn-default ui-closeDialog">关闭</button>
            </div>
</div>
            </form>
</div>

<script type="text/javascript">
    var $memberGroupId = $("#memberGroupId")
    $memberGroupId.SelectBind({ dataSourceFrom: "attr" });
    var groupId = Request("memberGroupId");
    if (groupId != "")
    {
        $memberGroupId.SetValue(groupId.toString());
    }
    $memberGroupId.change(function () {
        var groupId = $(this).val();
        location.href = "?memberGroupId=" + groupId;
    });
</script>